import request from '@/utils/request';

export interface LoginData {
  username: string;
  password: string;
}

export interface UserInfo {
  id: number;
  username: string;
  realName: string;
  avatar?: string;
  roles: string[];
  permissions: string[];
}

export interface LogoutParams {
  userId: number;
}

const Api = {
  Login: '/login',
  Logout: '/logout',
  GetRoleMenu: '/menu/findByMenu',

  // GetUserInfo: '/auth/getUserInfo',
  // Register: '/auth/register',
};

export const login = (data: LoginData) => {
  // 创建FormData对象
  const formData = new FormData();
  formData.append('username', data.username);
  formData.append('password', data.password);

  return request({
    url: Api.Login,
    method: 'post',
    data: formData,
    // 不需要手动设置Content-Type，request.ts中会处理
  });
};

// export const getUserInfo = () => {
//   return request({
//     url: Api.GetUserInfo,
//     method: 'get',
//   });
// };

export const logout = (params?: LogoutParams) => {
  return request({
    url: `${Api.Logout}/${params?.userId}`,
    method: 'get',
  });
};

export const getRoleMenu = () => {
  return request({
    url: Api.GetRoleMenu,
    method: 'get',
  });
};

// export const register = (data: LoginData) => {
//   return request({
//     url: Api.Register,
//     method: 'post',
//     data,
//   });
// }; 